package com.gagakuai.framework.form;

import org.camunda.bpm.engine.FormService;
import org.camunda.bpm.engine.form.FormField;
import org.camunda.bpm.engine.form.TaskFormData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/*
 * @program: common-starters
 * @description:
 * @author: houhong
 * @create: 2022-12-13 16:25
 */
@Component
public class FormTask {

    @Autowired
    private FormService formService;

    public void task(){

        String processDefiniKey = "";
        //拿到开始节点定义的表单key
        String startFormKey = formService.getStartFormKey(processDefiniKey);
    }

    public void taskForm(){

        /*
        *  表单查询：
         *      1：
        */
        String processDefiniKey = "";
        String taskDefiniKey = "";
        //拿到开始节点定义的表单key
        String taskFormKey = formService.getTaskFormKey(processDefiniKey, taskDefiniKey);
    }


    public void getForm(){

        /*
         *  表单查询：
         *      1：第一个流程定义Id
         *      2: 第二个是表单引擎,表单引擎默认是NulL，也可以是juel
         *      外置表单用 "juel",动态表单用Null
         */
        String processDefiniKey = "";
        String taskDefiniKey = "";
        //拿到开始节点定义的表单key
        Object renderedTaskForm = formService.getRenderedTaskForm(processDefiniKey, "juel");
    }



    public void getFormData(){

        /*
         *  表单查询：
         *      1：第一个流程定义Id
         *      2: 第二个是表单引擎,表单引擎默认是NulL，也可以是juel
         *      外置表单用 "juel",动态表单用Null
         */
        String processDefiniKey = "";
        String taskDefiniKey = "";
        //拿到任务节点表单数据
        TaskFormData taskFormData = formService.getTaskFormData("taskId");

        List<FormField> formFields = taskFormData.getFormFields();
        for (FormField formField : formFields) {
            String id = formField.getId();
            String label = formField.getLabel();
            Map<String, String> properties = 
                    formField.getProperties();
        }
    }
}